#pragma once

#ifdef _WIN32
#include <windows.h>  

class Win32MiniDump
{
public:
	static Win32MiniDump* s_pMiniDumper;
	static LPCRITICAL_SECTION s_pCriticalSection;

	_EXCEPTION_POINTERS *m_pExceptionInfo;
	TCHAR m_szMiniDumpPath[MAX_PATH];
	TCHAR m_szAppPath[MAX_PATH];
	TCHAR m_szAppBaseName[MAX_PATH];

	Win32MiniDump();
	~Win32MiniDump(void);

private:
	static long WINAPI UnhandledExceptionHandler(struct _EXCEPTION_POINTERS *pExceptionInfo);

	void SetMiniDumpFileName(void);
	bool CheckThreadToken(HANDLE* phToken);
	BOOL EnablePrivilege(LPCTSTR pszPriv, HANDLE hToken, TOKEN_PRIVILEGES* ptpOld);
	BOOL RestorePrivilege(HANDLE hToken, TOKEN_PRIVILEGES* ptpOld);
	long WriteMiniDump(_EXCEPTION_POINTERS *pExceptionInfo);
};
#endif